<?php

namespace App\Http\Controllers;

use DB;

use App\HealthyNum;

use App\Datatables;
use Illuminate\Http\Request;
use Storage;

class JkangController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * 健康号列表
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
     */
    public function jkList(Request $request)
    {
		if($request->isMethod('post')) {
            return response()->json(Datatables::JkList());
        }
        return view('jkang.jklist');
    }

    /**
     * 添加健康号
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
     */
    public function jkPublish(Request $request)
    {
        if ($request->isMethod('post')) {

            $return = HealthyNum::JkangPublish($request);
            if ($return['status'] === 1) {
                return redirect('/jiankang/list')->with('status', $return['status'])->with('message', $return['message']);
            } else {
                return back()->with('status', $return['status'])->with('message', $return['message']);
            }
        }

        return view('jkang.jkPublish');
    }


    /**
     * 修改健康号
     * @param Request $request
     * @param fenlei $fenlei
     * @return $this|\Illuminate\Http\RedirectResponse
     */
    public function jkModify(Request $request, HealthyNum $HealthyNum)
    {
        if ($request->isMethod('post')) {
            $return = HealthyNum::JkModify($request, $HealthyNum);
            return back()->with('status', $return['status'])->with('message', $return['message']);
        }
        return view('jkang.jkModify')->with(compact('HealthyNum'));
    }

    /**
     * 删除健康号
     * @param fenlei $fenlei
     * @return array
     * @throws \Exception 
     */
    public function jkDel($id, Request $request)
    {
		$jkhao = HealthyNum::where('id', $id)->exists();
        if (!$jkhao) return ['status' => 2, 'message' => '无此数据'];
        return HealthyNum::Del($id, $request);
    }
	
	
}